package com.jwgf.smarowindingmachine_unity.ui;

import com.jwgf.common.ViewCache;
import com.jwgf.smarowindingmachine_unity.R;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class MainMenuFragment extends MenuFragment implements OnClickListener {
    public static final String fragmentTag = "MainMenuFragment";
    private Button machineStateButton;
    private Button parameterSettingButton;
    private Button productManageButton;
    private Button equipmentMaintenanceButton;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = ViewCache.getInstance().getView(R.layout.fragment_main_menu);
//        View v = inflater
//                .inflate(R.layout.fragment_main_menu, container, false);
        machineStateButton = v.findViewById(R.id.machine_state_button);
        machineStateButton.setOnClickListener(this);
        parameterSettingButton = v.findViewById(R.id.parameter_setting_button);
        parameterSettingButton.setOnClickListener(this);
        productManageButton = v.findViewById(R.id.product_manage_button);
        productManageButton.setOnClickListener(this);
        equipmentMaintenanceButton = v.findViewById(R.id.equipment_maintenance_button);
        equipmentMaintenanceButton.setOnClickListener(this);

        machineStateButton.setSelected(true);
        return v;
    }

    @Override
    public void switchSelection(int id) {
        if (id == R.id.machine_state_button) {
            machineStateButton.setSelected(true);
            parameterSettingButton.setSelected(false);
            productManageButton.setSelected(false);
            equipmentMaintenanceButton.setSelected(false);
        } else if (id == R.id.parameter_setting_button) {
            machineStateButton.setSelected(false);
            parameterSettingButton.setSelected(true);
            productManageButton.setSelected(false);
            equipmentMaintenanceButton.setSelected(false);
        } else if (id == R.id.product_manage_button) {
            machineStateButton.setSelected(false);
            parameterSettingButton.setSelected(false);
            productManageButton.setSelected(true);
            equipmentMaintenanceButton.setSelected(false);
        } else if (id == R.id.equipment_maintenance_button) {
            machineStateButton.setSelected(false);
            parameterSettingButton.setSelected(false);
            productManageButton.setSelected(false);
            equipmentMaintenanceButton.setSelected(true);
        }
    }

    @Override
    public void onClick(View v) {
        SwitchPageManager.getInstance().switchMainMenu(getFragmentManager(), v.getId());
    }
}
